﻿using UnityEngine;
using System.Collections;

public class FadeInSprite : MonoBehaviour {

	public Color color_from = new Color(1f,1f,1f,0f);
	public Color color_to = new Color(1f,1f,1f,1f);
	public float speed = 1.0f;
	public float delay = 0.0f;
	private float t = 0.0f;
	
	
	// Use this for initialization
	void Start () {
		
		renderer.material.color = color_from;
		
	}
	
	public void Restart()
	{
		renderer.material.color = color_from;
		t=0;
	}
	
	// Update is called once per frame
	void Update () {
		
		if(t>=delay)
		{
			float per = t-delay;
			renderer.material.color = Color.Lerp (color_from,color_to,per);
			
			t += Time.deltaTime / speed;
		}
		else
			t += Time.deltaTime;
		
		
		
	}
}
